#include "adduserdialog.h"
#include "ui_adduserdialog.h"
#include "mainwindow.h"
#include "usersql.h"

addUserDialog::addUserDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::addUserDialog)
{
    ui->setupUi(this);
}

addUserDialog::~addUserDialog()
{
    delete ui;
}

void addUserDialog::on_btn_submit_clicked()
{
    QString name = ui->le_name->text();
    QString sex = ui->cb_sex->currentText();
    qDebug() << sex;
    QString id = ui->le_id->text();
    QString address = ui->le_address->text();
    QString phone = ui->le_phone->text();
    User user;
    user.name = name;
    user.sex = sex;
    user.idcard = id;
    user.address = address;
    user.phone = phone;
    auto ptr = MainWindow::getinstance();
    ptr->addUser(user);
    ptr->updateMainWindow();
    this->hide();
    ui->le_name->setText("");
    ui->cb_sex->setCurrentIndex(0);
    ui->le_id->setText("");
    ui->le_address->setText("");
    ui->le_phone->setText("");
}

void addUserDialog::on_btn_cancel_clicked()
{
    ui->le_name->setText("");
    ui->cb_sex->setCurrentIndex(0);
    ui->le_id->setText("");
    ui->le_address->setText("");
    ui->le_phone->setText("");
    this->hide();
}
